package chainofResponsibility;

/**
 * @Author: Ma JiBin
 * @Email: 1423553596@qq.com
 * @Date: 2018/9/10 15:50
 * @Description: 抽象日志记录类
 */
public abstract class AbstractLogger {
    public static int INFO = 1;
    public static int DEBUG = 2;
    public static int ERROR = 3;

    public int level;
    public AbstractLogger nextLogger;

    public void setNextLogger(AbstractLogger nextLogger) {
        this.nextLogger = nextLogger;
    }

    /**
     * 输出日志信息方法，调用write()方法
     *
     * @param level   日志级别
     * @param massage 日志信息
     */
    public void logMassage(int level, String massage) {
        if (this.level <= level) {
            write(massage);
        }
        if (nextLogger != null) {
            nextLogger.logMassage(level, massage);
        }
    }

    /**
     * 打印日志信息方法
     *
     * @param massage 需要记录的信息
     */
    public abstract void write(String massage);
}
